package model.components.nodes.factory;

import model.components.nodes.node.Node;
import org.apache.commons.collections15.Factory;

public class NodesFactory implements Factory< Node >
{
	private String networkName;
	public String getNetworkName(){ return networkName; }
	public void setNetworkName( String networkName ){ this.networkName = networkName; }
	
	protected int routersPercentage;
	public int getRoutersPercentage(){ return this.routersPercentage; }
	public void setRoutersPercentage( int routersPercentage ){ this.routersPercentage = routersPercentage; }
	
	protected int switchesPercentage;
	public int getSwitchesPercentage(){ return this.switchesPercentage; }
	public void setSwitchesPercentage( int switchesPercentage ){ this.switchesPercentage = switchesPercentage; }
	
	protected int serverPercentage;
	public int getServerPercentage(){ return this.serverPercentage; }
	public void setServerPercentage( int serverPercentage ){ this.serverPercentage = serverPercentage; }
	
	private int linuxPercentage;
	public int getLinuxPercentage(){ return linuxPercentage; }
	public void setLinuxPercentage( int linuxPercentage ){ this.linuxPercentage = linuxPercentage; }

	private int windowsPercentage;
	public int getWindowsPercentage(){ return windowsPercentage; }
	public void setWindowsPercentage( int windowsPercentage ){ this.windowsPercentage = windowsPercentage; }
	
	private int solarisPercentage;
	public int getSolarisPercentage(){ return solarisPercentage; }
	public void setSolarisPercentage( int solarisPercentage ){ this.solarisPercentage = solarisPercentage; }
	
	private int androidPercentage;
	public int getAndroidPercentage(){ return androidPercentage; }
	public void setAndroidPercentage( int androidPercentage ){ this.androidPercentage = androidPercentage; }
	
	private int vmWarePercentage;
	public int getVmWarePercentage(){ return vmWarePercentage; }
	public void setVmWarePercentage( int vmWarePercentage ){ this.vmWarePercentage = vmWarePercentage; }

	private int xenPercentage;
	public int getXenPercentage(){ return xenPercentage; }
	public void setXenPercentage( int xenPercentage ){ this.xenPercentage = xenPercentage; }
	
	private int kvmPercentage;
	public int getKvmPercentage(){ return kvmPercentage; }
	public void setKvmPercentage( int kvmPercentage ){ this.kvmPercentage = kvmPercentage; }
	
	private int umlPercentage;
	public int getUmlPercentage(){ return umlPercentage; }
	public void setUmlPercentage( int umlPercentage ){ this.umlPercentage = umlPercentage; }
	
	protected int minCpu;
	public int getMinCpu(){ return minCpu; }
	public void setMinCpu( int minCpu ){ this.minCpu = minCpu; }
	
	protected int maxCpu;
	public int getMaxCpu(){ return maxCpu; }
	public void setMaxCpu( int maxCpu ){ this.maxCpu = maxCpu; }
	
	protected int minMemory;
	public int getMinMemory(){ return minMemory; }
	public void setMinMemory( int minMemory ){ this.minMemory = minMemory; }
	
	protected int maxMemory;
	public int getMaxMemory(){ return maxMemory; }
	public void setMaxMemory( int maxMemory ){ this.maxMemory = maxMemory; }
	
	protected int minDiskSpace;
	public int getMinDiskSpace(){ return minDiskSpace; }
	public void setMinDiskSpace( int minDiskSpace ){ this.minDiskSpace = minDiskSpace; }
	
	protected int maxDiskSpace;
	public int getMaxDiskSpace(){ return maxDiskSpace; }
	public void setMaxDiskSpace( int maxDiskSpace ){ this.maxDiskSpace = maxDiskSpace; }
	
	protected int nodeCount;
	public int getNodeCount(){ return this.nodeCount; }
	public void setNodeCount( int nodeCount ){ this.nodeCount = nodeCount; }

	public NodesFactory( String networkName, int routersPercentage, int switchesPercentage, int serverPercentage, int linuxPercentage, int windowsPercentage, int solarisPercentage, int androidPercentage, int vmWarePercentage, int xenPercentage, int kvmPercentage, int umlPercentage, int minCpu, int maxCpu, int minMemory, int maxMemory, int minDiskSpace, int maxDiskSpace )
	{
		this.setNetworkName( networkName );
		
		this.setRoutersPercentage( routersPercentage );
		this.setSwitchesPercentage( switchesPercentage );
		this.setServerPercentage( serverPercentage );
		
		this.setLinuxPercentage( linuxPercentage );
		this.setWindowsPercentage( windowsPercentage );
		this.setSolarisPercentage( solarisPercentage );
		this.setAndroidPercentage( androidPercentage );
		
		this.setVmWarePercentage( vmWarePercentage );
		this.setXenPercentage( xenPercentage );
		this.setKvmPercentage( kvmPercentage );
		this.setUmlPercentage( umlPercentage );
		
		this.setMinCpu( minCpu );
		this.setMaxCpu( maxCpu );
		
		this.setMinMemory( minMemory );
		this.setMaxMemory( maxMemory );
		
		this.setMinDiskSpace( minDiskSpace );
		this.setMaxDiskSpace( maxDiskSpace );			
	}
	
	@Override
	public Node create()
	{
		return null;
	}
	
	protected String randomOperatingSystem()
	{
		double randomOperatingSystem = 100 * Math.random();
		
		if( 0 <= randomOperatingSystem && randomOperatingSystem < this.getLinuxPercentage() )
			return Node.LINUX_OS;
		
		else if( this.getLinuxPercentage() <= randomOperatingSystem && randomOperatingSystem < this.getLinuxPercentage() + this.getWindowsPercentage() )
			return Node.WINDOWS_OS;
		
		else if( this.getLinuxPercentage() + this.getWindowsPercentage() <= randomOperatingSystem && randomOperatingSystem < this.getLinuxPercentage() + this.getWindowsPercentage() + this.getSolarisPercentage() )
			return Node.SOLARIS_OS;
		
		else if( this.getLinuxPercentage() + this.getWindowsPercentage() + this.getSolarisPercentage() <= randomOperatingSystem && randomOperatingSystem < 100 )
			return Node.ANDROID_OS;
		
		return null;
	}
	
	protected String randomVirtualEnvironment()
	{
		double randomVirtualEnvironment = 100 * Math.random();
		
		if( 0 <= randomVirtualEnvironment && randomVirtualEnvironment < this.getVmWarePercentage() )
			return Node.VMWARE_VE;
		
		else if( this.getVmWarePercentage() <= randomVirtualEnvironment && randomVirtualEnvironment < this.getVmWarePercentage() + this.getXenPercentage() )
			return Node.XEN_VE;
		
		else if( this.getVmWarePercentage() + this.getXenPercentage() <= randomVirtualEnvironment && randomVirtualEnvironment < this.getVmWarePercentage() + this.getXenPercentage() + this.getKvmPercentage() )
			return Node.KVM_VE;
		
		else if( this.getVmWarePercentage() + this.getXenPercentage() + this.getKvmPercentage() <= randomVirtualEnvironment && randomVirtualEnvironment < 100 )
			return Node.UML_VE;
		
		return null;
	}
	
	protected int randomCpu()
	{
		return this.getMinCpu() + (int)( Math.random() * ( ( this.getMaxCpu() - this.getMinCpu() ) + 1 ) );
	}
	
	protected int randomMemory()
	{
		return this.getMinMemory() + (int)( Math.random() * ( ( this.getMaxMemory() - this.getMinMemory() ) + 1 ) );
	}
	
	protected int randomDiskSpace()
	{
		return this.getMinDiskSpace() + (int) (Math.random() * ( ( this.getMaxDiskSpace() - this.getMinDiskSpace() ) + 1 ) );
	}
	
}
